package com.winspread.app.map

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations
import com.winspread.mvvm.base.m.BaseViewModel

/**
 *Author: Amin
 *Data: 2022/4/20 11:00
 *
 *Description:
 *
 * map和switchMap 返回的为可监听的livedata
 *
 * map 的函数返回的是livedata 泛型 的数据
 *
 * switchMap 的函数返回为 livedata 数据
 *
 */
class MyViewModel : BaseViewModel() {

    val userLiveData = MutableLiveData<User>()

    val userName: LiveData<String> = Transformations.map(userLiveData) { user ->
        return@map rw.getString(user.lastName)
    }

    private val rw = Rw()

    val s: LiveData<String> = Transformations.switchMap(userLiveData) { user ->
        rw.getList(user.firstName)
    }


}